package edu.ynu.se.xiecheng.achitectureclass.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0")
public class Device extends LogicEntity {
    @Column
    private String name;
    @Column(nullable = false, unique = true)
    private String DeviceSerialNumber;
    @Column
    private String Unit;
    @Column
    private String MonitorAddresses;
    @Column(nullable = false, unique = true)
    private String Type;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = {"devices"})
    private Greenhouse greenhouse;

    @OneToMany(mappedBy = "device",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties("device")
    private Set<Camera> cameras;

    @OneToMany(mappedBy = "device",
            cascade = CascadeType.ALL)
    private Set<AirTemperature> airTemperatures;

    @OneToMany(mappedBy = "device",
            cascade = CascadeType.ALL)
    private Set<CarbonDioxide> carbonDioxides;

    @OneToMany(mappedBy = "device",
            cascade = CascadeType.ALL)
    private Set<SoilMoistureContent> soilMoistureContents;

    @OneToMany(mappedBy = "device",
            cascade = CascadeType.ALL)
    private Set<SoilTemperature> soilTemperatures;

    @OneToMany(mappedBy = "device",
            cascade = CascadeType.ALL)
    private Set<SoilPH> soilPHs;
}
